﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;
using JM.JCY.Common;
using JM.JCY.Common.Utilities;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.LawArchives.LawCaseMaterialView
{
    public partial class LawCaseMaterialViewUserControl : UserControl
    {
        public int _caseId
        {
            set { ViewState["_caseId"] = value; }
            get { return (int)ViewState["_caseId"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (LawCaseProxy proxy = new LawCaseProxy())
                {
                    if (Request.QueryString["CaseId"] != null)
                    {
                        _caseId = Int32.Parse(Request.QueryString["CaseId"].ToString());
                    }
                    // load data
                    var loadDT = proxy.GetLawCaseMaterial(_caseId, string.Empty);
                    this.lblTitle.Text = loadDT[0].Year + "年扣押冻结物品情况一览表";
                    LoadForEdit(loadDT);
                    LoadForView(loadDT);
                }

            }

            // switch controls
            if (this.hfIsEdit.Value != "1")
                SwitchControls(true, false);
            else
                SwitchControls(false, true);
        }

        private void LoadForView(LawCaseDataSet.T_LawCaseMaterialDataTable dt)
        {
            var editRow = dt[0];

            this.lblBuildDate.Text = editRow.BuildDate.ToString(JCYConstant.Date_Format_CN);
            this.lblHandDate.Text = editRow.HandDate.ToString(JCYConstant.Date_Format_CN);
            this.lblHandleDate.Text = editRow.HandleDate.ToString(JCYConstant.Date_Format_CN);
            this.lblReturnDate.Text = editRow.ReturnDate.ToString(JCYConstant.Date_Format_CN);
            this.lblTurnOverDate.Text = editRow.TurnOverDate.ToString(JCYConstant.Date_Format_CN);
            this.lblFillDept.Text = editRow.FillDept;
            this.lblFiller.Text = editRow.Filler;
            this.lblHandBy.Text = editRow.HandBy;
            this.lblHandlelSituation.Text = editRow.HandlelSituation;
            this.lblInvolvedBy.Text = editRow.InvolvedBy;
            this.lblOthers.Text = editRow.Others;
            this.lblReceiveBy.Text = editRow.ReceiveBy;
            this.lblRemark.Text = editRow.Remark;
            this.lblStuffCount.Text = editRow.StuffCount.ToString();
            this.lblStuffName.Text = editRow.StuffName;
            this.lblYear.Text = editRow.Year;
        }

        private void LoadForEdit(LawCaseDataSet.T_LawCaseMaterialDataTable dt)
        {
            var editRow = dt[0];

            this.txtFillDept.Text = editRow.FillDept;
            this.txtFiller.Text = editRow.Filler;
            this.txtHandBy.Text = editRow.HandBy;
            this.txtHandlelSituation.Text = editRow.HandlelSituation;
            this.txtInvolvedBy.Text = editRow.InvolvedBy;
            this.txtOthers.Text = editRow.Others;
            this.txtReceiveBy.Text = editRow.ReceiveBy;
            this.txtRemark.Text = editRow.Remark;
            this.txtStuffCount.Text = editRow.StuffCount.ToString();
            this.txtStuffName.Text = editRow.StuffName;
            this.txtYear.Text = editRow.Year;

            this.hfBuildDate.Value = editRow.BuildDate.ToString();
            this.hfHandDate.Value = editRow.HandDate.ToString();
            this.hfHandleDate.Value = editRow.HandleDate.ToString();
            this.hfReturnDate.Value = editRow.ReturnDate.ToString();
            this.hfTurnOverDate.Value = editRow.TurnOverDate.ToString();
        }

        private void SwitchControls(bool isLabelsShow, bool isControlsShow)
        {
            // labels
            this.lblBuildDate.Visible = isLabelsShow;
            this.lblFillDept.Visible = isLabelsShow;
            this.lblFiller.Visible = isLabelsShow;
            this.lblHandBy.Visible = isLabelsShow;
            this.lblHandDate.Visible = isLabelsShow;
            this.lblHandleDate.Visible = isLabelsShow;
            this.lblHandlelSituation.Visible = isLabelsShow;
            this.lblInvolvedBy.Visible = isLabelsShow;
            this.lblOthers.Visible = isLabelsShow;
            this.lblReceiveBy.Visible = isLabelsShow;
            this.lblRemark.Visible = isLabelsShow;
            this.lblReturnDate.Visible = isLabelsShow;
            this.lblStuffCount.Visible = isLabelsShow;
            this.lblStuffName.Visible = isLabelsShow;
            this.lblTurnOverDate.Visible = isLabelsShow;
            this.lblYear.Visible = isLabelsShow;

            //controls
            this.txtFillDept.Visible = isControlsShow;
            this.txtFiller.Visible = isControlsShow;
            this.txtHandBy.Visible = isControlsShow;
            this.txtHandlelSituation.Visible = isControlsShow;
            this.txtInvolvedBy.Visible = isControlsShow;
            this.txtOthers.Visible = isControlsShow;
            this.txtReceiveBy.Visible = isControlsShow;
            this.txtRemark.Visible = isControlsShow;
            this.txtStuffCount.Visible = isControlsShow;
            this.txtStuffName.Visible = isControlsShow;
            this.txtYear.Visible = isControlsShow;
            this.dtBuildDate.Visible = isControlsShow;
            this.dtHandDate.Visible = isControlsShow;
            this.dtHandleDate.Visible = isControlsShow;
            this.dtReturnDate.Visible = isControlsShow;
            this.dtTurnOverDate.Visible = isControlsShow;
            this.hr8.Visible = isControlsShow;

        }
    }
}
